package leetcode.code1185;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {
	static int[] monthDays = new int[] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	static String[] week = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
			"Saturday", };
	static int[] daysOfYear;// daysOfYear[2022] 2022年之前有多少天
	static int[] daysOfMonth;// daysOfMonth[6] 6月之前有多少天
	static int YearStart = 1900;
	static int YearEnd = 2100;
	static int month = 12;
	static {
		daysOfYear = new int[YearEnd + 1];
		for (int i = YearStart + 1; i <= YearEnd; i++) {
			daysOfYear[i] += sumDays(i - 1) + daysOfYear[i - 1];
		}
		daysOfMonth = new int[month + 1];
		for (int i = 2; i <= month; i++) {
			daysOfMonth[i] = monthDays[i - 1] + daysOfMonth[i - 1];
		}
	}

	private static int sumDays(int year) {
		if (isLeapYear(year)) {
			return 366;
		}
		return 365;
	}

	// 判断闰年
	private static boolean isLeapYear(int year) {
		return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
	}

	public String dayOfTheWeek(int day, int month, int year) {
		int days = daysOfYear[year] + daysOfMonth[month] + day;
		if (month > 2 && isLeapYear(year)) {
			days += 1;
		}
		return week[days % 7];
	}

	@Override
	public void debug1() {
		HelpDebug.compare("Saturday", this.dayOfTheWeek(31, 8, 2019));

	}

	public void debug0() {
		HelpDebug.compare("Monday", this.dayOfTheWeek(1, 1, 1900));

	}

	@Override
	public void debug2() {
		HelpDebug.compare("Monday", this.dayOfTheWeek(3, 1, 2022));

	}

	@Override
	public void debug3() {
		HelpDebug.compare("Sunday", this.dayOfTheWeek(18, 7, 1999));

	}

	@Override
	public void debug4() {
		HelpDebug.compare("Sunday", this.dayOfTheWeek(15, 8, 1993));

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug0();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
